<?php
require_once("lib/autoload.php");

#header('Content-type: application/json');

extract($_GET);
$arguments = array();

if (isset($type) && $type!= "all") {
    $arguments["type"] = $type;
}
if (isset($creator) && $creator!= "all") {
    $arguments["creator"] = $creator;
}
if (isset($from) && strlen($from) > 0) {
    $arguments["from"] = $from;
}
if (isset($to) && strlen($to) > 0) {
    $arguments["to"] = $to;
}
if (isset($tags)) {
    $arguments["tags"] = $tags;
}  
if (isset($page)) {
    $arguments["page"] = (int) $page;
}
if (isset($pageSize)) {
    $arguments["pageSize"] = (int) $pageSize;
}
if (isset($sortBy)) {
    $arguments["sortBy"] = $sortBy;
}


$dc = new DataController();
$dc->connect();    
$actionsPage = $dc->getActions($arguments);
$dc->disconnect();

$ar = array();

if ($actionsPage != NULL) {
    foreach($actionsPage->getActions() as $action) {
        $ar[] = $action-> getJsonArray();
    }
    print json_encode(array("success"=>true,
                            "total"=>$actionsPage->getTotal(),
                            "page"=>$actionsPage->getPageIndex(),
                            "pageSize"=>$actionsPage->getPageSize(),
                            "actions"=>$ar));
}
else {
    print json_encode(array("success"=>false));
}



?>